﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using Common;
using StedySoft.SenseSDK;
using StedySoft.SenseSDK.DrawingCE;
using System.Drawing;
using Microsoft.Drawing;
namespace MLogix
{
    public partial class SMSFilter : Form
    {
        private bool Auto = false;
        System.Threading.Thread workerThread;
        bool appRunning = true;
        private string password = string.Empty;
        private bool newLogin = false;
        private bool changePassword = false;
        private Microsoft.WindowsCE.Forms.InputPanel sip;

        #region Controls Def
        #region /****************************LOGON SCREEN****************************/
        SensePanelTextboxItem _sensePassword = new SensePanelTextboxItem("sensePassword");
        SensePanelTextboxItem _senseConfirm = new SensePanelTextboxItem("senseConfirm");
        SensePanelButtonItem _sensePassOK = new SensePanelButtonItem("sensePassOK");
        SensePanelCheckboxItem _senseChangePass = new SensePanelCheckboxItem("senseChangePass");
        #endregion /****************************LOGON SCREEN****************************/

        #region/****************************MAIN SCREEN CONTROLS****************************/
        //Filters
        SensePanelDividerItem _senseFilterDivider = new SensePanelDividerItem("senseFilterDivider", ReadCustomText.GetString("T_FILTERS"));
        SensePanelMoreItem _senseUserFilterPanel = new SensePanelMoreItem("senseUserFilterPanel");//Panel to define user filters
        SensePanelMoreItem _senseMessageFilterPanel = new SensePanelMoreItem("senseMessageFilterPanel");//Panel to define message filters
        //SMS
        SensePanelDividerItem _senseSMSDivider = new SensePanelDividerItem("senseSMSDivider", ReadCustomText.GetString("T_SMS"));
        SensePanelMoreItem _senseViewPanel = new SensePanelMoreItem("senseViewPanel");//Panel to view Contacts and their sms
        SensePanelButtonItem _senseCustomSendSMS = new SensePanelButtonItem("senseCustomSendSMS");
        //Settings
        SensePanelDividerItem _senseSettingsDivider = new SensePanelDividerItem("senseSettingsDivider", ReadCustomText.GetString("T_SETTINGS"));
        SensePanelMoreItem _senseSettings = new SensePanelMoreItem("senseSettings");
        #endregion/****************************MAIN SCREEN CONTROLS****************************/

        #region/****************************CONTACT AND MESSAGE PANEL****************************/
        SensePanelTextboxItem _senseAddFilter = new SensePanelTextboxItem("senseAddFilter");
        SensePanelButtonItem _senseBttnAddFilter = new SensePanelButtonItem("senseBttnAddFilter");
        SensePanelButtonItem _senseBttnLoadFile = new SensePanelButtonItem("senseBttnLoadFile");
        SensePanelButtonItem _senseBttnPhoneBook = new SensePanelButtonItem("senseBttnPhoneBook");
        #endregion/****************************CONTACT AND MESSAGE PANEL****************************/

        #region/****************************VIEW SMS PANEL****************************/
        SensePanelComboItem _senseContactsDD = new SensePanelComboItem("senseContactsDD");// DDL which will contain all the filtered contacts
        //View SMS
        SensePanelDividerItem _senseDivider = new SensePanelDividerItem("senseDivider", ReadCustomText.GetString("T_VIEWSMS"));
        SensePanelMoreItem _senseViewSMSList = new SensePanelMoreItem("senseViewSMSList");
        SensePanelMoreItem _senseViewSentSMSList = new SensePanelMoreItem("senseViewSentSMSList");
        SensePanelButtonItem _senseBttnExportSMS = new SensePanelButtonItem("senseBttnExportSMS");
        //New SMS
        SensePanelDividerItem _senseNewMessages = new SensePanelDividerItem("senseNewMessages", ReadCustomText.GetString("T_NEWMESSAGES"));
        #endregion/****************************VIEW SMS PANEL****************************/

        #region/****************************SETTINGS PANEL****************************/
        //Filter Status
        SensePanelDividerItem _senseFilterModeDivider = new SensePanelDividerItem("senseFilterModeDivider", ReadCustomText.GetString("T_FILTERMODE"));
        SensePanelOnOffItem _senseSwitchFilter = new SensePanelOnOffItem("senseSwitchFilter");
        //----Custom Notification
        SensePanelDividerItem _senseNotifyDivider = new SensePanelDividerItem("senseNotifyDivider", ReadCustomText.GetString("T_NOTISETTINGS"));
        //----Enable disable notification (Should control below settings
        SensePanelOnOffItem _senseNotificationEnabled = new SensePanelOnOffItem("senseNotificationEnabled");
        //----Set notification to silent or loud mode
        SensePanelCheckboxItem _senseSilentMode = new SensePanelCheckboxItem("senseSilentMode");
        SensePanelTextboxItem _senseCustomMessage = new SensePanelTextboxItem("senseCustomMessage");
        //----Enable disable quickLaunchkey 
        SensePanelOnOffItem _senseEnableQuickLaunchKey = new SensePanelOnOffItem("senseEnableQuickLaunchKey");
        //Customize outbox
        SensePanelDividerItem _senseOutboxDivider = new SensePanelDividerItem("_senseOutbox", ReadCustomText.GetString("T_OUTBOXSETTING"));
        SensePanelOnOffItem _senseSaveSentMessage = new SensePanelOnOffItem("senseSaveSentMessage");
        SensePanelOnOffItem _senseSaveSentMessageAlert = new SensePanelOnOffItem("senseSaveSentMessageAlert");
        #endregion/****************************SETTINGS PANEL****************************/
        #endregion Controls Def

        public SMSFilter(bool mode, bool init)
        {
            Auto = mode;
            if (init)
                InitializeComponent();
            //DBOPS.SenseMessagesDB.handlechange += new DBOPS.SenseMessagesDB.D(SenseMessagesDB_handlechange);
            SMS.messageSent += new SMS.SendDelegate(SMSFilter_messageSent);
        }

        void SMSFilter_messageSent(bool sent)
        {
            if (sent)
                ThreadRefresh();
        }

        //void SenseMessagesDB_handlechange(bool a)
        //{
        //   // SenseAPIs.SenseMessageBox.Show(a.ToString(), "TEST", SenseMessageBoxButtons.OK);
        //   // if (a)
        //    //    ThreadRefresh();
        //}

        private void AddItems()
        {
            _sensePassword.LabelText = ReadCustomText.GetString("T_PASSWORD");// "Password:";
            _sensePassword.Text = "";
            _sensePassword.KeyPress += new KeyPressEventHandler(_sensePassword_KeyPress);
            _sensePassword.PasswordChar = '*';
            _senseConfirm.LabelText = ReadCustomText.GetString("T_CNFMPASS");// "Confirm Password:";
            _senseConfirm.PasswordChar = '*';
            _senseConfirm.Text = "";
            _sensePassOK.Text = ReadCustomText.GetString("T_OK");// "OK";
            _senseChangePass.PrimaryText = ReadCustomText.GetString("T_CHANGEPASS");// "Change Password";
            _senseUserFilterPanel.PrimaryText = ReadCustomText.GetString("T_CONTACTFILTER");// "Contact Filters";
            _senseMessageFilterPanel.PrimaryText = ReadCustomText.GetString("T_MSGFILTER");// "Message Filters";
            _senseViewPanel.PrimaryText = ReadCustomText.GetString("T_VIEWMESSAGES");// "View Messages";
            _senseContactsDD.LabelText = ReadCustomText.GetString("T_CHOOSECONTACT");// "Choose Contact";

            _senseNewMessages.Text = ReadCustomText.GetString("T_NEWMESSAGES");

            _senseViewSMSList.PrimaryText = ReadCustomText.GetString("T_VIEWALLSMSFRM");// "View all SMS from:";
            _senseViewSentSMSList.PrimaryText = ReadCustomText.GetString("T_VIEWSENTSMSTO");
            _senseBttnExportSMS.LabelText = ReadCustomText.GetString("T_EXPORTCSV");// "Export SMS to CSV";
            _senseBttnExportSMS.Text = ReadCustomText.GetString("T_EXPORT");//"Export";
            _senseAddFilter.LabelText = ReadCustomText.GetString("T_ADDFILTER");// "Add Filter:";
            _senseBttnAddFilter.Text = ReadCustomText.GetString("T_ADD");// "Add";
            _senseBttnLoadFile.Text = ReadCustomText.GetString("T_LOADFILE");// "Load from file";
            _senseBttnPhoneBook.Text = ReadCustomText.GetString("T_GETPHONEBOOK");// "Get contact from phone book";
            //TODO: Add message in text file
            //_senseBttnRefresh.Text = ReadCustomText.GetString("T_REFRESH");//NEW
            //_senseBttnRefresh.LabelText = ReadCustomText.GetString("T_REFRESHSMSLIST");//NEW
            _senseCustomSendSMS.Text = ReadCustomText.GetString("T_CHOOSENSEND");
            _senseCustomSendSMS.LabelText = ReadCustomText.GetString("T_CUSTCONTACTSMS");
            //Settings Labels
            _senseSettings.PrimaryText = ReadCustomText.GetString("T_SETTINGS");//"Settings";
            _senseSettings.SecondaryText = ReadCustomText.GetString("T_CUSTOMIZESETTINGS");//"Customize the settings";
            _senseFilterModeDivider.Text = ReadCustomText.GetString("T_FILTERSTATUS");//"Filter Status";
            _senseSwitchFilter.PrimaryText = ReadCustomText.GetString("T_FILTERINGENABLED");//"Filtering Enabled";
            _senseSwitchFilter.SecondaryText = ReadCustomText.GetString("T_TODISABLEOFF");//"To disable, switch to OFF mode";
            _senseNotifyDivider.Text = ReadCustomText.GetString("T_CUSTOMIZENOTIFICATIONALERT");//"Customize notification alert";
            _senseNotificationEnabled.PrimaryText = ReadCustomText.GetString("T_NOTIFICATIONINACTIVE");//"Notification Inactive";
            _senseNotificationEnabled.SecondaryText = ReadCustomText.GetString("T_TOENABLEON");//"To enable, switch to ON mode";
            _senseSilentMode.PrimaryText = ReadCustomText.GetString("T_NOSOUNDONNEW");//"No sound on new message";
            _senseSilentMode.SecondaryText = ReadCustomText.GetString("T_SETSNOTIFSOUND");//"Set the notification's sound";
            _senseCustomMessage.LabelText = ReadCustomText.GetString("T_DISPLAYCUSTOMMESSAGE");//"Display your custom message:";
            _senseEnableQuickLaunchKey.PrimaryText = ReadCustomText.GetString("T_QKEYDISABLED");//"Quick Launch key Disabled";
            _senseEnableQuickLaunchKey.SecondaryText = ReadCustomText.GetString("T_TOENABLEON");//"To enable, switch to ON mode";
            _senseOutboxDivider.Text = ReadCustomText.GetString("T_CONFIGUREOUTBOX");//"Configure outbox";
            _senseSaveSentMessage.PrimaryText = ReadCustomText.GetString("T_SAVESENTMODEOFF");
            _senseSaveSentMessage.SecondaryText = ReadCustomText.GetString("T_TOENABLEON");
            _senseSaveSentMessageAlert.PrimaryText = ReadCustomText.GetString("T_SMSSENTALERTOFF");
            _senseSaveSentMessageAlert.SecondaryText = ReadCustomText.GetString("T_TOENABLEON");
            //Events
            _senseCustomSendSMS.OnClick += new SensePanelButtonItem.ClickEventHandler(_senseCustomSendSMS_OnClick);
            _sensePassOK.OnClick += new SensePanelButtonItem.ClickEventHandler(sensePassOK_OnClick);
            _senseChangePass.OnStatusChanged += new SensePanelCheckboxItem.StatusEventHandler(senseChangePass_OnStatusChanged);
            _senseContactsDD.OnSelectedIndexChanged += new SensePanelComboItem.SelectedIndexChangedEventHandler(senseContactsDD_OnSelectedIndexChanged);
            _senseBttnAddFilter.OnClick += new SensePanelButtonItem.ClickEventHandler(_senseBttnAddFilter_OnClick);
            _senseBttnPhoneBook.OnClick += new SensePanelButtonItem.ClickEventHandler(_senseBttnPhoneBook_OnClick);
            _senseBttnLoadFile.OnClick += new SensePanelButtonItem.ClickEventHandler(_senseBttnLoadFile_OnClick);
            _senseBttnExportSMS.OnClick += new SensePanelButtonItem.ClickEventHandler(_senseBttnExportSMS_OnClick);
            //Settings events
            _senseSwitchFilter.OnStatusChanged += new SensePanelOnOffItem.StatusEventHandler(_senseSwitchFilter_OnStatusChanged);
            _senseNotificationEnabled.OnStatusChanged += new SensePanelOnOffItem.StatusEventHandler(_senseNotificationEnabled_OnStatusChanged);
            _senseSilentMode.OnStatusChanged += new SensePanelCheckboxItem.StatusEventHandler(_senseSilentMode_OnStatusChanged);
            _senseEnableQuickLaunchKey.OnStatusChanged += new SensePanelOnOffItem.StatusEventHandler(_senseEnableQuickLaunchKey_OnStatusChanged);
            _senseSaveSentMessage.OnStatusChanged += new SensePanelOnOffItem.StatusEventHandler(_senseSaveSentMessage_OnStatusChanged);
            _senseSaveSentMessageAlert.OnStatusChanged += new SensePanelOnOffItem.StatusEventHandler(_senseSaveSentMessageAlert_OnStatusChanged);
            
            this._senseListMain.ContextMenu = null;
            this._senseListMain.BeginUpdate();
            this._senseListMain.AddItem(_sensePassword);
            this._senseListMain.AddItem(_senseConfirm);
            this._senseListMain.AddItem(_sensePassOK);
            this._senseListMain.AddItem(_senseChangePass);
            this._senseListMain.AddItem(_senseFilterDivider);
            this._senseListMain.AddItem(_senseUserFilterPanel);
            this._senseListMain.AddItem(_senseMessageFilterPanel);
            this._senseListMain.AddItem(_senseSMSDivider);
            this._senseListMain.AddItem(_senseViewPanel);
            this._senseListMain.AddItem(_senseCustomSendSMS);
            this._senseListMain.AddItem(_senseSettingsDivider);
            this._senseListMain.AddItem(_senseSettings);


            //this._senseViewPanel.Children.Add(_senseBttnRefresh);
            this._senseViewPanel.Children.Add(_senseContactsDD);
            this._senseViewPanel.Children.Add(_senseDivider);
            this._senseViewPanel.Children.Add(_senseViewSMSList);
            this._senseViewPanel.Children.Add(_senseViewSentSMSList);
            this._senseViewPanel.Children.Add(_senseBttnExportSMS);

            this._senseViewPanel.Children.Add(_senseNewMessages);

            //Settings
            this._senseSettings.Children.Add(_senseFilterModeDivider);
            this._senseSettings.Children.Add(_senseSwitchFilter);
            this._senseSettings.Children.Add(_senseNotifyDivider);
            this._senseSettings.Children.Add(_senseNotificationEnabled);
            this._senseSettings.Children.Add(_senseSilentMode);
            this._senseSettings.Children.Add(_senseCustomMessage);
            this._senseSettings.Children.Add(_senseEnableQuickLaunchKey);
            this._senseSettings.Children.Add(_senseOutboxDivider);
            this._senseSettings.Children.Add(_senseSaveSentMessage);
            this._senseSettings.Children.Add(_senseSaveSentMessageAlert);
            //SIP
            this.sip = new Microsoft.WindowsCE.Forms.InputPanel(this.components);
            SIP.Enable(this._senseListMain.Handle);

            _senseViewSMSList.Enabled = false;
            _senseViewSentSMSList.Enabled = false;
            _senseBttnExportSMS.Enabled = false;
            this.sip.EnabledChanged += new EventHandler(sip_EnabledChanged);


            this._senseListMain.EndUpdate();
            SetInitialVisibility();
            LoadFilter();
            LoadContactsDropDown();
            GetPassword();
            GetSettings();
            StartWorkerThread();
        }

        
        private void StartWorkerThread()
        {
            //DBOPS.SenseMessagesDB.SetFormVariable(ref messageSent);
            workerThread = new System.Threading.Thread(MonitorRegistry);
            workerThread.IsBackground = true;

        }

        public void MonitorRegistry()
        {

            while (this.appRunning)
            {
                string contact = string.Empty;
                if (NotificationControl.IsNewMessageAvailable(out contact))
                {
                    SenseAPIs.SenseMessageBox.Show(ReadCustomText.GetString("T_NEWMESSAGEFROM") + " " + contact, SMSFILTER, SenseMessageBoxButtons.OK);
                    ThreadRefresh();
                }
                //else if (DBOPS.SenseMessagesDB.Messagesent)
                //{
                //   // SenseAPIs.SenseMessageBox.Show("In Thread", "TEST", SenseMessageBoxButtons.OK);
                //    ThreadRefresh();
                //    DBOPS.SenseMessagesDB.Messagesent = false;
                //}

                Thread.Sleep(1000);
            }
            workerThread.Abort();
        }

        public void ThreadRefresh()
        {
            //SenseAPIs.SenseMessageBox.Show(this.InvokeRequired.ToString(), "In refresh", SenseMessageBoxButtons.OK);
            if (this.InvokeRequired)
            {
                this.Invoke((Action)(() => { _senseBttnRefresh_OnClick(null); }));
            }
            else
                _senseBttnRefresh_OnClick(null);
        }

        private void GetLatestMessages()
        {
            DBOPS.SenseMessagesDB.GetNewMessages(ref _senseViewPanel);
        }

        private void GetReadModeLatestMessages()
        {
            DBOPS.SenseMessagesDB.GetReadModeNewMessages(ref _senseListMain);
        }

        private void SetInitialVisibility()
        {
            this._senseConfirm.Visible = false;
            this._senseMessageFilterPanel.Visible = false;
            this._senseUserFilterPanel.Visible = false;
            this._senseViewPanel.Visible = false;
            this._senseSettingsDivider.Visible = false;
            this._senseSMSDivider.Visible = false;
            this._senseCustomSendSMS.Visible = false;
            this._senseFilterDivider.Visible = false;
            this._senseSettings.Visible = false;
        }

        private void LoadContactsDropDown()
        {

            DBOPS.SenseMessagesDB.FillContactList(ref this._senseContactsDD);
            if (this._senseContactsDD.Items.Count() != 0)
            {
                this._senseContactsDD.Enabled = true;
                this._senseContactsDD.SelectedIndex = 0;
            }
            else
                this._senseContactsDD.Enabled = false;
        }

        private void LoadFilter()
        {
            this._senseUserFilterPanel.Children.Add(_senseAddFilter);
            this._senseMessageFilterPanel.Children.Add(_senseAddFilter);
            this._senseUserFilterPanel.Children.Add(_senseBttnAddFilter);
            this._senseMessageFilterPanel.Children.Add(_senseBttnAddFilter);
            this._senseUserFilterPanel.Children.Add(_senseBttnLoadFile);
            this._senseMessageFilterPanel.Children.Add(_senseBttnLoadFile);
            this._senseUserFilterPanel.Children.Add(_senseBttnPhoneBook);

            int count = 0;
            DBOPS.SenseFilterDB.FillFilters(ref this._senseMessageFilterPanel, ref this._senseUserFilterPanel);
            foreach (SenseListControl.ISenseListItem itm in this._senseUserFilterPanel.Children)
            {
                if (count > 3)
                    (itm as SensePanelItem).OnClick += new SensePanelItem.ClickEventHandler(pi_OnClick);
                count++;
            }
            count = 0;
            foreach (SenseListControl.ISenseListItem itm in this._senseMessageFilterPanel.Children)
            {
                if (count > 2)
                    (itm as SensePanelItem).OnClick += new SensePanelItem.ClickEventHandler(pi_OnClick);
                count++;
            }
        }

        private void SetValidVisibility()
        {
            GetLatestMessages();
            this._senseListMain.BeginUpdate();
            this._sensePassOK.Visible = false;
            this._sensePassword.Visible = false;
            this._senseChangePass.Visible = false;
            this._senseConfirm.Visible = false;
            this._senseMessageFilterPanel.Visible = true;
            this._senseUserFilterPanel.Visible = true;
            this._senseViewPanel.Visible = true;
            this._senseFilterDivider.Visible = true;
            this._senseCustomSendSMS.Visible = true;
            this._senseSMSDivider.Visible = true;
            this._senseSettingsDivider.Visible = true;
            this._senseSettings.Visible = true;
            this._senseListMain.EndUpdate();
        }

        private void SetChangePasswordVisibility()
        {
            this._senseListMain.BeginUpdate();
            if (changePassword)
                this._sensePassword.LabelText = ReadCustomText.GetString("T_NEWPASS");// "New Password";
            this._senseConfirm.Visible = true;
            this._senseMessageFilterPanel.Visible = false;
            this._senseUserFilterPanel.Visible = false;
            this._senseViewPanel.Visible = false;
            this._senseCustomSendSMS.Visible = false;
            this._senseListMain.EndUpdate();
        }

        private void SetReadVisible()
        {
            this._senseListMain.BeginUpdate();
            this._sensePassOK.Visible = false;
            this._sensePassword.Visible = false;
            this._senseChangePass.Visible = false;
            this._senseConfirm.Visible = false;
            this._senseMessageFilterPanel.Visible = false;
            this._senseUserFilterPanel.Visible = false;
            this._senseViewPanel.Visible = false;
            this._senseCustomSendSMS.Visible = false;
            this._senseFilterDivider.Visible = false;
            this._senseSMSDivider.Visible = false;
            this._senseSettingsDivider.Visible = false;
            this._senseSettings.Visible = false;

            this._senseViewPanel.Children.Remove(_senseContactsDD);
            this._senseViewPanel.Children.Remove(_senseDivider);
            this._senseViewPanel.Children.Remove(_senseViewSMSList);
            this._senseViewPanel.Children.Remove(_senseViewSentSMSList);
            this._senseViewPanel.Children.Remove(_senseBttnExportSMS);
            this._senseListMain.RemoveItem(_senseViewPanel);

            this._senseListMain.AddItem(_senseContactsDD);
            this._senseListMain.AddItem(_senseDivider);
            this._senseListMain.AddItem(_senseViewSMSList);
            this._senseListMain.AddItem(_senseViewSentSMSList);
            GetReadModeLatestMessages();
            this._senseListMain.EndUpdate();
        }

        private void menuAbtSMSFilter_Click(object sender, EventArgs e)
        {
            AboutSMSFilter.Show();

            //StedySoft.SenseSDK.DrawingCE.SenseAPIs.SenseMessageBox.Show("SMS Filter v2.4\n Private SMS Filtering APP by\n Mohit Sapru", "SMS Filter", SenseMessageBoxButtons.OK);
        }

        private void menuAbtSense_Click(object sender, EventArgs e)
        {
            StedySoft.SenseSDK.DrawingCE.SenseAPIs.SenseAboutBox.Show();
        }

        private void SetSettingsVisibleState(bool disable)
        {
            _senseNotificationEnabled.Enabled = !disable;
            _senseSilentMode.Enabled = !disable;
            _senseCustomMessage.Enabled = !disable;
            _senseEnableQuickLaunchKey.Enabled = !disable;
            _senseSaveSentMessage.Enabled = !disable;
            _senseSaveSentMessageAlert.Enabled = !disable;
        }

        private void SetSubNotificationVisibleState(bool disable)
        {
            _senseSilentMode.Enabled = !disable;
            _senseCustomMessage.Enabled = !disable;
            _senseEnableQuickLaunchKey.Enabled = !disable;
        }

        private void GetSettings()
        {
            InterceptorControl.SetSaveAppRegPath();
            if (InterceptorControl.GetInterceptorStatus())
            {
                _senseSwitchFilter.Status = ItemStatus.On;
                _senseSwitchFilter.PrimaryText = ReadCustomText.GetString("T_FILTERINGENABLED");// "Filtering Enabled";
                _senseSwitchFilter.SecondaryText = ReadCustomText.GetString("T_TODISABLEOFF");// "To disable, switch to OFF mode";
                SetSettingsVisibleState(false);
            }
            else
            {
                _senseSwitchFilter.Status = ItemStatus.Off;
                _senseSwitchFilter.PrimaryText = ReadCustomText.GetString("T_FILTERINGDISABLED");//Filtering Disabled";
                _senseSwitchFilter.SecondaryText = ReadCustomText.GetString("T_TOENABLEON");//"To enable, switch to ON mode";
                SetSettingsVisibleState(true);
            }
            if (NotificationControl.GetStatus())
            {
                _senseNotificationEnabled.Status = ItemStatus.On;// : ItemStatus.Off;
                _senseNotificationEnabled.PrimaryText = ReadCustomText.GetString("T_NOTIFICATIONACTIVE");//"Notifiation Active";
                _senseNotificationEnabled.SecondaryText = ReadCustomText.GetString("T_TODISABLEOFF");//"To disable, switch to OFF mode";
                SetSubNotificationVisibleState(false);
            }
            else
            {
                _senseNotificationEnabled.Status = ItemStatus.Off;
                _senseNotificationEnabled.PrimaryText = ReadCustomText.GetString("T_NOTIFICATIONINACTIVE");//"Notifiation Inactive";
                _senseNotificationEnabled.SecondaryText = ReadCustomText.GetString("T_TOENABLEON");//"To enable, switch to ON mode";
                SetSubNotificationVisibleState(true);
            }
            if (!NotificationControl.GetMode())
            {
                //ON
                _senseSilentMode.Status = ItemStatus.On;
                _senseSilentMode.PrimaryText = ReadCustomText.GetString("T_SOUNDONNEW");//"Play sound on new message";
            }
            else
            {
                //OFF
                _senseSilentMode.Status = ItemStatus.Off;
                _senseSilentMode.PrimaryText = ReadCustomText.GetString("T_NOSOUNDONNEW");//"No sound on new message";
            }
            if (NotificationControl.GetQuickStartMode())
            {
                _senseEnableQuickLaunchKey.Status = ItemStatus.On;
                _senseEnableQuickLaunchKey.PrimaryText = ReadCustomText.GetString("T_QKWYENABLED");//"Quick Launch key Enabled";
                _senseEnableQuickLaunchKey.SecondaryText = ReadCustomText.GetString("T_TODISABLEOFF");//"To disable, switch to OFF mode";

            }
            else
            {
                _senseEnableQuickLaunchKey.Status = ItemStatus.Off;
                _senseEnableQuickLaunchKey.PrimaryText = ReadCustomText.GetString("T_QKEYDISABLED");//"Quick Launch key Disabled";
                _senseEnableQuickLaunchKey.SecondaryText = ReadCustomText.GetString("T_TOENABLEON");//"To enable, switch to ON mode";
            }

            if (NotificationControl.GetSaveSentMode())
            {
                _senseSaveSentMessage.Status = ItemStatus.On;
                _senseSaveSentMessage.PrimaryText = ReadCustomText.GetString("T_SAVESENTMODEON");
                _senseSaveSentMessage.SecondaryText = ReadCustomText.GetString("T_TODISABLEOFF");
            }
            else
            {
                _senseSaveSentMessage.Status = ItemStatus.Off;
                _senseSaveSentMessage.PrimaryText = ReadCustomText.GetString("T_SAVESENTMODEOFF");
                _senseSaveSentMessage.SecondaryText = ReadCustomText.GetString("T_TOENABLEON");
            }
            if (NotificationControl.GetDeliveryMode())
            {
                _senseSaveSentMessageAlert.Status = ItemStatus.On;
                _senseSaveSentMessageAlert.PrimaryText = ReadCustomText.GetString("T_SMSSENTALERTON");
                _senseSaveSentMessageAlert.SecondaryText = ReadCustomText.GetString("T_TODISABLEOFF");
            }
            else
            {
                _senseSaveSentMessageAlert.Status = ItemStatus.Off;
                _senseSaveSentMessageAlert.PrimaryText = ReadCustomText.GetString("T_SMSSENTALERTOFF");
                _senseSaveSentMessageAlert.SecondaryText = ReadCustomText.GetString("T_TOENABLEON");
            }

            _senseCustomMessage.Text = NotificationControl.GetMessage();

        }

        private void GetPassword()
        {

            if (DBOPS.SensePasswordDB.SelectPassword(out password))
            {
                //Has password
                newLogin = false;
                changePassword = false;

            }
            else
            {
                newLogin = true;
                SenseAPIs.SenseMessageBox.Show(ReadCustomText.GetString("T_NEWLOGIN")/*"New Login! Create Password"*/, SMSFILTER, SenseMessageBoxButtons.OK);
                SetChangePasswordVisibility();
                //new password
            }

        }

        private void SMSFilter_Closing(object sender, CancelEventArgs e)
        {
            menuExit_Click(null, e);
        }

        void SMSFilter_Closed(object sender, System.EventArgs e)
        {
            _senseListMain.Clear();
            _senseListMain.Dispose();
        }

    }

    #region Class AboutSMSFilter
    internal sealed class AboutSMSFilter
    {
        private static DialogResult _dr = DialogResult.None;

        internal static DialogResult Show()
        {
            using (ITranslucentForm f = new ITranslucentForm())
            {
                f.SuspendLayout();
                f.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
                f.ClientSize = new System.Drawing.Size(240, 320);
                f.ControlBox = false;
                f.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                f.Location = new System.Drawing.Point(0, 0);
                f.MinimizeBox = false;
                f.Name = "AboutSMSFilter";
                f.WindowState = System.Windows.Forms.FormWindowState.Maximized;
                f.ResumeLayout(false);
                f.OnRender += new ITranslucentForm.OnRenderEventHandler(OnRender);
                f.OnSenseClick += new ITranslucentForm.OnMouseClickEventHandler(OnSenseClick);
                f.ShowDialog();
            }
            return _dr;
        }

        static void OnSenseClick(object sender)
        {
            _dr = DialogResult.OK;
            (sender as Form).Close();
        }

        static void OnRender(Graphics g)
        {
            // get the height/width of screen
            int h = Screen.PrimaryScreen.Bounds.Height;
            int w = Screen.PrimaryScreen.Bounds.Width;

            // get the vertical center
            int screenCenter = h / 2;

            // get the SenseSDK image from the resource assembly
            IImage iimg = SenseAPIs.SenseImage.LoadIImageFromFile(Win32.location + @"\327.png");

            // get the size and readjust for VGA/QVGA
            Size sz = SenseAPIs.SenseImage.GetIImageSize(iimg);
            if (!Resolution.ScreenIsVGA) { sz.Width /= 1; sz.Height /= 1; }

            // center the image in the top half of the screen and draw
            int offsetX = (int)Math.Round((double)(((double)w / 2.0) - ((double)sz.Width / 2.0)));
            int offsetY = (int)Math.Round((double)(((double)screenCenter / 2.0) - ((double)sz.Height / 2.0)));
            g.DrawImageAlphaChannel(iimg, new Rectangle(offsetX, offsetY, sz.Width, sz.Height));
            SenseAPIs.SenseImage.ReleaseIImage(iimg);

            // draw the version string relative to the SenseSDK image size and placement
            using (Font f = new Font("Helvetica Neue OTS", 5.5f, FontStyle.Italic))
            {
                string s = "Version: 2.5";
                SizeF stringSize = g.MeasureString(s, f);
                Rectangle r = new Rectangle(offsetX, offsetY + (sz.Height / 1) + 5, sz.Width - 10, (int)stringSize.Height);
                using (Brush b = new SolidBrush(Color.White))
                {
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.Alignment = StringAlignment.Far;
                        sf.FormatFlags = StringFormatFlags.NoWrap;
                        g.DrawString(s, f, b, r, sf);
                    }
                }
            }

            // draw the copyright string (3) in the horizontal center of the lower half of the screen
            using (Font f = new Font("Helvetica Neue OTS", 8f, FontStyle.Italic))
            {
                string s = "A SMS Filter app by Mohit Sapru";
                SizeF stringSize = g.MeasureString(s, f);
                int p = (int)Math.Ceiling((stringSize.Width + 1) / (w - (Resolution.LRMargin * 2)));
                int v = (int)((h / 2 - p * stringSize.Height) / 2);
                Rectangle r = new Rectangle(2, offsetY + (sz.Height / 1) + 15, (w - (Resolution.LRMargin * 2)) - 1, (h / 2) - 1 - 2 * v);
                using (Brush b = new SolidBrush(Color.White))
                {
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.Alignment = StringAlignment.Center;
                        g.DrawString(s, f, b, r, sf);
                    }
                }
            }
           // draw the copyright string (3) in the horizontal center of the lower half of the screen
             using (Font f = new Font("Helvetica Neue OTS", 8f, FontStyle.Italic))
            {
                string s = "Special thanks to all the Donors @ XDA: ZVONKO, Luigi, DONFANO, Samvds, krapshack, defaultdotxbe, bernabap, Woaloo, roencaco, kusnier, Bonusbartus, mh297      ";
                SizeF stringSize = g.MeasureString(s, f);
                int p = (int)Math.Ceiling((stringSize.Width + 1) / (w - (Resolution.LRMargin * 2)));
                int v = (int)((h / 2 - p * stringSize.Height) / 2);
                Rectangle r = new Rectangle(Resolution.LRMargin, h / 2 + v, (w - (Resolution.LRMargin * 2)) - 1, (h / 2) - 1 - 2 * v);
                using (Brush b = new SolidBrush(Color.White))
                {
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.Alignment = StringAlignment.Center;
                        g.DrawString(s, f, b, r, sf);
                    }
                }
            }
        }
    }
    #endregion
}